package com.wzdigit.wms.wms.service.order;

import com.wzdigit.wms.basic.domain.dtos.putaway.PutawayDto;
import com.wzdigit.wms.basic.domain.order.PutawayTask;
import com.wzdigit.wms.basic.domain.order.PutawayTaskDtl;
import com.wzdigit.wms.wms.service.core.putaway.PutawayTaskDtlService;
import com.wzdigit.wms.wms.service.core.putaway.PutawayTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * <p>
 * 上架任务 业务类
 * </p>
 *
 * @author
 * @since 2021-01-12
 */
@Service
@Slf4j
public class PutawayService {

    @Autowired
    PutawayTaskService putawayTaskService;

    @Autowired
    PutawayTaskDtlService putawayTaskDtlService;


    /**
     * 生成上架任务
     * 生成上架任务、上架任务明细
     *
     * @param putawayDto
     * @return
     */
    public PutawayDto addNewOne(PutawayDto putawayDto) {

        //生成上架任务
        PutawayTask putawayTask = putawayDto.getPutawayTask();
        putawayTask = putawayTaskService.addNewOne(putawayTask);

        final Integer putawayTaskId = putawayTask.getPutawayTaskId();
        //生成上架任务明细
        List<PutawayTaskDtl> putawayTaskDtlList = putawayDto.getPutawayTaskDtlList();
        putawayTaskDtlList.stream().forEach(s -> s.setPutawayTaskId(putawayTaskId));

        putawayTaskDtlList = putawayTaskDtlService.addNewList(putawayTaskDtlList);

        //设置回参
        putawayDto.setPutawayTask(putawayTask).setPutawayTaskDtlList(putawayTaskDtlList);

//        Result<PutawayRequest> result = new Result<>();
//        result.setData(putawayRequest);
        return putawayDto;
    }


    /**
     * 更新上架任务
     * 更新上架任务、上架任务明细
     *
     * @param putawayDto
     * @return
     */
    public PutawayDto updateOne(PutawayDto putawayDto) {

        //更新上架任务
        PutawayTask putawayTask = putawayDto.getPutawayTask();
        putawayTask = putawayTaskService.updateOne(putawayTask);

        //更新上架任务明细
        List<PutawayTaskDtl> putawayTaskDtlList = putawayDto.getPutawayTaskDtlList();
        putawayTaskDtlService.updateList(putawayTaskDtlList);

        //设置回参
        putawayDto.setPutawayTask(putawayTask).setPutawayTaskDtlList(putawayTaskDtlList);

//        Result<PutawayRequest> result = new Result<>();
//        result.setData(putawayRequest);
        return putawayDto;
    }
}
